// pages/ai/index.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    IMGBASEURL: app.globalData.IMGBASEURL,
    color: "200",
    spaceType: [
      {
        id: "65e2f3052c4a5f0d85df2c5b",
        src: app.globalData.IMGBASEURL + "kt.png",
        name: "客厅",
        describe: "家居住宅",
        uploadName: "客厅平层",
        spaceType: 0,
        skytype: 1,
      },
      {
        id: "65e2f3052c4a5f0d85df2c62",
        src: app.globalData.IMGBASEURL + "ws.png",
        name: "卧室",
        describe: "家居住宅",
        uploadName: "主卧平层",
        spaceType: 0,
        skytype: 1,
      },
      {
        id: "65e2f3052c4a5f0d85df2c5d",
        src: app.globalData.IMGBASEURL + "cf.png",
        name: "厨房",
        describe: "家居住宅",
        uploadName: "餐厅平层",
        spaceType: 0,
        skytype: 1,
      },
      {
        id: "65e2f3052c4a5f0d85df2c60",
        src: app.globalData.IMGBASEURL + "sf.png",
        name: "书房",
        describe: "家居住宅",
        uploadName: "书房",
        spaceType: 0,
        skytype: 1,
      },
      {
        id: "65e2f3052c4a5f0d85df2c65",
        src: app.globalData.IMGBASEURL + "etf.png",
        name: "儿童房",
        describe: "家居住宅",
        uploadName: "儿童房",
        spaceType: 0,
        skytype: 1,
      },
      {
        id: "65eadc531b50c5c5105b7a40",
        src: app.globalData.IMGBASEURL + "bs.png",
        name: "别墅",
        describe: "住宅建筑",
        uploadName: "1-2层外观",
        spaceType: 1,
        skytype: 3,
      },
      {
        id: "65eec84be12de1bd47257a81",
        src: app.globalData.IMGBASEURL + "ty.png",
        name: "庭院",
        describe: "景观",
        uploadName: "后庭院",
        spaceType: 2,
        skytype: 2,
      },
    ],
    bottomCustom: "",
  },
  //跳转页面
  toPage(e) {
    // if (!wx.getStorageSync('token')) {
    //   const popup = this.selectComponent('#popupid');
    //   popup.setData({
    //     visible: true
    //   })
    //   return
    // }
    wx.navigateTo({
      url: "/pages/ai/creativeHall/index",
      success(res) {
        res.eventChannel.emit("aiAuthoringParameters", e.currentTarget.dataset);
        wx.removeStorageSync("shareImg"); //清除生图上传回显地址
      },
    });
  },
  //跳转引导下载页
  toDownloadApp() {
    wx.navigateTo({
      url: "/pages/ai/downloadApp/index",
    });
  },
  openLoginPo() {
    const popup = this.selectComponent("#popupid");
    popup.setData({
      visible: true,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      IMGBASEURL: app.globalData.IMGBASEURL,
    });
    this.calculatedBottomHeight();
    // wx.removeStorageSync('drawingParameter') //每次进入都需要清除一次生图参数
    // wx.removeStorageSync('createImgInfo')
    // wx.removeStorageSync('styleStr') //清除海报分享参数
    // wx.removeStorageSync('shareImg')
    const keysToRemove = [
      "drawingParameter",
      "createImgInfo",
      "styleStr",
      "shareImg",
    ];
    keysToRemove.forEach((key) => {
      wx.removeStorageSync(key);
    });
  },

  // 计算底部安全距离
  calculatedBottomHeight() {
    const systemInfo = wx.getSystemInfoSync();
    const windowHeight = systemInfo.windowHeight; // 可用窗口高度
    const screenHeight = systemInfo.screenHeight; // 屏幕总高度
    const safeAreaBottom = screenHeight - windowHeight; // 底部安全距离（近似值）
    let heightCustom = safeAreaBottom <= 64 ? 130 : 145;
    this.setData({
      bottomCustom: heightCustom,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getTabBar().init();
    const popup = this.selectComponent("#popupid");
    popup.setData({
      visible: false,
    });
    app.getUserStatus(this).then();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},
});
